<?php
App::import('Vendor','tcpdf/tcpdf');
ob_end_clean();
$tcpdf = new TCPDF();
$textfont = 'helvetica';

$tcpdf->SetAuthor("RO-MA");
$tcpdf->SetAutoPageBreak(true);
$tcpdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$tcpdf->setPrintHeader(false);
$tcpdf->setPrintFooter(false);
 
$tcpdf->SetTextColor(0, 0, 0);
$tcpdf->SetFont($textfont,'',8);
$tcpdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// include 1D barcode class (search for installation path)
require_once(dirname(__FILE__).'/tcpdf_barcodes_1d_include.php');
// set the barcode content and type
$barcodeobj = new TCPDFBarcode('http://www.tcpdf.org', 'C128');
// output the barcode as HTML object


$style = array(
    'position' => '',
    'align' => 'C',
    'stretch' => false,
    'fitwidth' => true,
    'cellfitalign' => '',
    'border' => true,
    'hpadding' => 'auto',
    'vpadding' => 'auto',
    'fgcolor' => array(0,0,0),
    'bgcolor' => false, //array(255,255,255),
    'text' => true,
    'font' => 'helvetica',
    'fontsize' => 8,
    'stretchtext' => 2
);
$tarjeta=1;

foreach ($service_order_rows as $order): 
    if (($tarjeta == 1) or ($tarjeta == 3) or ($tarjeta == 5) or ($tarjeta == 7)) {
        $tcpdf->AddPage('P', 'A4');        
    }
    $htmlcontent = '';
    //Generación del codigo de barra
    $cod_barra = 'codigobarra';
    $codigo = $tcpdf->serializeTCPDFtagParameters(array($service_order['ServiceOrder']['client_id'].'-'.$service_order['ServiceOrder']['numero_orden_de_servicio'].'-'.$order['ServiceOrderRow']['id'], 'C39', '', '', 50, 30, 0.4, array('position'=>'S', 'border'=>true, 'padding'=>1, 'fgcolor'=>array(0,0,0), 'bgcolor'=>array(255,255,255), 'text'=>true, 'font'=>'helvetica', 'fontsize'=>7, 'stretchtext'=>4), 'N'));
    // create some HTML content




    $htmlcontent1 = '<table style="float:left" border="1" cellspacing="2" cellpadding="0">
        <tr>
            <th bgcolor="#cccccc" align="center" colspan="2"><h1>RO-MA</h1></th>
            <th bgcolor="#cccccc" align="center" colspan="4">Documento no válido como factura<br />Tarjetas de seguimiento de cubiertas -Taller de renovación</th>
            <th bgcolor="#cccccc" align="center" colspan="2">Nro ORDEN: <h2>'.$order['ServiceOrderRow']['id'].'</h2></th>
            <th align="center" colspan="2">OBS: '.$order['ServiceOrderRow']['observacion'].' - '.$order['ServiceOrderRow']['tipo_de_trabajo'].'</th>
        </tr>
        <tr>
            <td bgcolor="#cccccc" align="center" colspan="2">ORDEN RECEPCION</td>
            <td bgcolor="#cccccc" align="center" colspan="4">CLIENTE</td>
            <td bgcolor="#cccccc" align="center" colspan="1">UNIDAD</td>
            <td bgcolor="#cccccc" align="center" colspan="1">FECHA</td>
            <td bgcolor="#cccccc" align="center" colspan="2">TRABAJO A REALIZAR</td>
        </tr>
        <tr>
            <td align="center" colspan="2"><h3>'.$service_order['ServiceOrder']['numero_orden_de_servicio'].'</h3></td>
            <td align="center" colspan="4">'. $service_order['ServiceOrder']['client_id'] . ' - ' . $service_order['Client']['nombre'] .'</td>
            <td align="center" colspan="1">'.$order['ServiceOrderRow']['unidad'].'</td>
            <td align="center" colspan="1">'.$service_order['ServiceOrder']['fecha'].'</td>
            <td align="center" colspan="2">'.$order['Article']['descripcion'].'</td>
        </tr>
        <tr>
            <td bgcolor="#cccccc" align="center" colspan="1">TIPO</td>
            <td bgcolor="#cccccc" align="center" colspan="1">MEDIDA</td>
            <td bgcolor="#cccccc" align="center" colspan="2">MARCA</td>
            <td bgcolor="#cccccc" align="center" colspan="2">NRO SERIE</td>
            <td bgcolor="#cccccc" align="center" colspan="2">FECHA EST. RETIRO</td>
            <td bgcolor="#cccccc" align="center" colspan="2">REALIZADO:</td>
        </tr>
        <tr>
            <td align="center" colspan="1">'.$order['ServiceOrderRow']['tipo'].'</td>
            <td align="center" colspan="1">'.$order['ServiceOrderRow']['medida'].'</td>
            <td align="center" colspan="2">'.$order['CubiertaMarca']['nombre'].'</td>
            <td align="center" colspan="2">'.$order['ServiceOrderRow']['numero_de_serie'].'</td>
            <td align="center" colspan="2">'.$service_order['ServiceOrder']['fecha_estimada_retiro'].'</td>
            <td align="center" colspan="2"></td>
        </tr>
        <tr>
            <td bgcolor="#cccccc" align="center" colspan="2">Recap. Anteriores:</td>
            <td align="center" colspan="6"></td>
            <td align="center" colspan="2"></td>
        </tr>
        <tr>
            <td bgcolor="#cccccc" align="center" colspan="2">Reparac. Anteriores:</td>
            <td align="center" colspan="6"></td>
            <td align="center" colspan="2"></td>
            
        </tr>
        <tr>
            <td bgcolor="#cccccc" align="center" colspan="2">Inapta - Motivo:</td>
            <td align="center" colspan="6"></td>
            <td align="center" colspan="2"></td>
        </tr>
        <tr>
            <td bgcolor="#cccccc" align="center" colspan="2">Radio de pulido:</td>
            <td align="center" colspan="3"></td>
            <td bgcolor="#cccccc" align="center" colspan="1">Hora:</td>
            <td align="center" colspan="2"></td>
            <td align="center" colspan="2"></td>
        </tr>
        <tr>
            <td bgcolor="#cccccc" align="center" colspan="1">P. Flux:</td>
            <td bgcolor="#cccccc" align="center" colspan="1">Hora:</td>
            <td align="center" colspan="6"></td>        
            <td align="center" colspan="2"></td>
        </tr>
        <tr>
            <td bgcolor="#cccccc" align="center" colspan="1">Cojin:</td>
            <td bgcolor="#cccccc" align="center" colspan="1">Hora:</td>
            <td align="center" colspan="2"></td>
            <td bgcolor="#cccccc" align="center" colspan="1">Lote:</td>
            <td align="center" colspan="1"></td>
            <td bgcolor="#cccccc" align="center" colspan="1">Hora:</td>
            <td align="center" colspan="1"></td>
            <td align="center" colspan="2"></td>
        </tr>
        <tr>    
            <td bgcolor="#cccccc" align="center" colspan="2">Banda anillo diseño:</td>
            <td align="center" colspan="3"></td>
            <td bgcolor="#cccccc" align="center" colspan="1">Lote:</td>
            <td align="center" colspan="2"></td>
            <td align="center" colspan="2"></td>
        </tr>
        <tr>
            <td bgcolor="#cccccc" align="center" colspan="1">Envelope:</td>
            <td align="center" colspan="1"></td>
            <td bgcolor="#cccccc" align="center" colspan="2">Nro Inner:</td>
            <td align="center" colspan="2"></td>
            <td bgcolor="#cccccc" align="center" colspan="1">Cámara:</td>
            <td align="center" colspan="1"></td>
            <td align="center" colspan="2"></td>
        </tr>
        <tr>
            <td bgcolor="#cccccc" align="center" colspan="2">Autoclave:</td>
            <td bgcolor="#cccccc" align="center" colspan="1">Grande:</td>
            <td align="center" colspan="2"></td>
            <td bgcolor="#cccccc" align="center" colspan="1">Chica:</td>
            <td align="center" colspan="2"></td>
            <td align="center" colspan="2"></td>
        </tr>
        <tr>
            <td bgcolor="#cccccc" align="center" colspan="2">Recarac. Efectuadas:</td>
            <td align="center" colspan="6"></td>
            <td align="center" colspan="2"></td>
        </tr>
        <tr>
            <td bgcolor="#cccccc" align="center" colspan="2">Inspección Final:<br /><br /></td>
            <td align="center" colspan="6"></td>
            <td align="center" colspan="2"></td>
        </tr>
    </table>';
    $htmlcontent2 = '<table style="float:right" border="1" cellspacing="2" cellpadding="6">
        <tr><td width="70%" align="center"><h2>ORDEN DE RECEPCION: '.$service_order['ServiceOrder']['numero_orden_de_servicio'].' - '.$order['ServiceOrderRow']['unidad'].'</h2></td></tr>
        
        <tr><td bgcolor="#cccccc" align="center"><h3>Código cubierta:</h3></td></tr>
        <tr><td align="center"><tcpdf align="center" method="write1DBarcode" params="'.$codigo.'"/></td>
        </tr>

        <tr ><th bgcolor="#cccccc" align="center"><h3>Cliente:</h3></th></tr>
        <tr><td align="center"><p><span style="font-size: 25; font-weight: bold;">' . $service_order['Client']['nombre'] .'</span></p></td></tr>

    </table>';
     $htmlcontent = '<table border="0">
        <tr>
            <td width="470">'.$htmlcontent1.'</td>
            <td width="10"></td>
            <td width="420">'.$htmlcontent2.'</td>

        </tr>
        </table>';    
    $tcpdf->writeHTML($htmlcontent, true, 0, true, 0);

    if (($tarjeta == 1) or ($tarjeta == 3) or ($tarjeta == 5) or ($tarjeta == 7))
    {
        $htmlcontent = "<br /><br />------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<br /><br />";
        $tcpdf->writeHTML($htmlcontent, true, 0, true, 0);
    }

    $tarjeta++;
endforeach;
unset($order);

 
// output the HTML content
//$tcpdf->writeHTML($htmlcontent, true, 0, true, 0);
//$tcpdf->writeHTML($html, true, false, true, false, '');
//$tcpdf->writeHTML($contenido, true, 0, true, 0);
//$tcpdf->LastPage();
$tcpdf->Output('miPdf.pdf', 'I');
?>